<template>
  <div>
    <div class="edit-top">
      <div class="common-tab">
        <a :href="'/#/publishScore?matchId='+scheduleInfo.matchId+'&scheduleId='+scheduleNewId" target="_blank">
          <el-button class="no-btn">{{scheduleInfo.matchCode}}</el-button>
        </a>
      </div>
      <div class="common-tab">
        <div class="group-vs-text">
          <div class="tab-text">{{scheduleInfo.scheduleName}}</div>
        </div>
        <div class="common-tab" style="margin-top: 5px;margin-left: 20px;">
          <div class="common-tab">
            <el-select v-model="scheduleInfo.matchStatus1" >
              <el-option label="" value=""></el-option>
              <el-option label="预赛" value="预赛"></el-option>
              <el-option label="复赛" value="复赛"></el-option>
              <el-option label="决赛" value="决赛"></el-option>
            </el-select>
          </div>
          <div class="common-tab">
            <el-select v-model="scheduleInfo.matchStatus2" >
              <el-option label="" value=""></el-option>
              <el-option label="太极一章" value="太极一章"></el-option>
              <el-option label="太极二章" value="太极二章"></el-option>
              <el-option label="太极三章" value="太极三章"></el-option>
              <el-option label="太极四章" value="太极四章"></el-option>
              <el-option label="太极五章" value="太极五章"></el-option>
              <el-option label="太极六章" value="太极六章"></el-option>
              <el-option label="太极七章" value="太极七章"></el-option>
              <el-option label="太极八章" value="太极八章"></el-option>
              <el-option label="高丽" value="高丽"></el-option>
              <el-option label="太白" value="太白"></el-option>
              <el-option label="平原" value="平原"></el-option>
              <el-option label="十进" value="十进"></el-option>
              <el-option label="地跆" value="地跆"></el-option>
              <el-option label="天拳" value="天拳"></el-option>
              <el-option label="汉水" value="汉水"></el-option>
              <el-option label="一如" value="一如"></el-option>
              <el-option label="自创品势" value="自创品势"></el-option>
            </el-select>
          </div>
          <div class="common-tab" >
            <el-button type="primary" plain style="height: 40px;" @click="matchScheduleChange">确定</el-button>
          </div>
        </div>
      </div>
      <div class="common-tab" style="width: 190px; margin-left: 25px;">
        <div>
          <div class="common-tab">
            <img src="@/assets/images/buttom-direction.png" style="height: 20px;height: 20px; padding: 0 10px 0 10px;"  @click="buttomSchedule">
          </div>
          <div class="common-tab" style="width: 100px">
            <el-select v-model="scheduleNewId" @change="getScheduleInfoNewData()">
              <el-option :label="item.matchCode" :value="item.id"  :key="index" v-for="(item,index) in matchScheduleForCodeList"></el-option>
            </el-select>
          </div>
          <div class="common-tab" >
            <img src="@/assets/images/top-direction.png" style="height: 20px;height: 20px; padding: 0 10px 0 10px;" @click="topSchedule">
          </div>
        </div>
        <div v-if="this.$store.state.user.matchAdminId != 8888">
          <el-button v-if="scheduleInfo.isLocked==1" style="background: red" class="edit-lock-btn" @click="unjumpToSchedule(scheduleInfo.lockId)">解锁</el-button>
          <el-button v-else class="edit-lock-btn" @click="jumpToSchedule(scheduleInfo.matchId, scheduleInfo.id)">锁定</el-button>
        </div>
      </div>
    </div>
    <div class="edit-group-box" style="margin-bottom: 10px;" v-if="scheduleInfo.type === 1 && !scheduleInfo.twoTime">
      <div class="common-tab" >
        <el-input v-model="scheduleInfo.blueTeam" style="width: 200px; border: 2px #0070C0 solid;height: 40px;" />
      </div>
      <div class="common-tab" >
        <el-input v-model="scheduleInfo.bluePlayer" style="width: 200px; border: 2px #0070C0 solid;height: 40px;" />
      </div>
      <div class="common-tab" v-for="(item,index) in matchLogicScoreList" :key="index">
        <div class="common-tab" style="border: 2px #548235 solid; width: 80px; border-radius: 5px;">
          <div class="tab-text">A {{item.accuracyScore}}</div>
          <div class="tab-text">P {{item.expressivenessScore}}</div>
        </div>
        <div class="common-tab" style="border: 2px #548235 solid; width: 80px; border-radius: 5px;height: 52px;" >
          <div class="tab-text" style="color: #ffffff;background: green">{{item.totalScore}}</div>
        </div>
      </div>
    </div>
    <div class="edit-group-box" style="margin-bottom: 10px;" v-if="scheduleInfo.type == 1 && scheduleInfo.twoTime">
      <div class="common-tab" >
        <el-input v-model="scheduleInfo.blueTeam" style="width: 200px; border: 2px #0070C0 solid;height: 40px;" />
      </div>
      <div class="common-tab" >
        <el-input v-model="scheduleInfo.bluePlayer" style="width: 200px; border: 2px #0070C0 solid;height: 40px;" />
      </div>
      <div class="common-tab" v-for="(item,index) in matchLogicScoreList" v-if="item.type == 1 || item.type == 2" :key="index">
        <div class="common-tab" v-if="item.type == 1" style="border: 2px #548235 solid; width: 80px; border-radius: 5px;">
          <div class="tab-text">A {{item.accuracyScore}}</div>
          <div class="tab-text">P {{item.expressivenessScore}}</div>
        </div>
        <div class="common-tab" v-if="item.type == 2" style="border: 2px #548235 solid; width: 80px; border-radius: 5px;">
          <div class="tab-text">A {{item.accuracyScore}}</div>
          <div class="tab-text">P {{item.expressivenessScore}}</div>
        </div>
        <div class="common-tab" @click="lockTwoTimeChanage1(item.type)" style="border: 2px #548235 solid; width: 80px; border-radius: 5px;height: 52px;" >
          <div v-if="scheduleInfo.lockTwoTime == item.type" class="common-tab" style="border: 2px #548235 solid; width: 80px; border-radius: 5px;height: 52px;" >
            <div class="tab-text" style="color: #ffffff;background: green">{{item.totalScore}}</div>
          </div>
          <div v-else class="tab-text">{{item.totalScore}}</div>
        </div>
      </div>
    </div>
    <div class="edit-group-box" style="margin-bottom: 40px;" v-else-if="scheduleInfo.type === 2 && !scheduleInfo.twoTime">
      <div>
        <div class="common-tab" >
          <el-input v-model="scheduleInfo.blueTeam" style="width: 200px; border: 2px #0070C0 solid;height: 40px;" />
        </div>
        <div class="common-tab" >
          <el-input v-model="scheduleInfo.bluePlayer" style="width: 200px; border: 2px #0070C0 solid;height: 40px;" />
        </div>
        <div class="common-tab" >
          <div class="common-tab" style="border: 2px #548235 solid; width: 80px; border-radius: 5px;">
            <div class="tab-text">A --</div>
            <div class="tab-text">P --</div>
          </div>
          <div class="common-tab" style="border: 2px #548235 solid; width: 80px; border-radius: 5px;height: 52px;" >
            <div class="tab-text" style="color: #ffffff;background: green">--</div>
          </div>
        </div>
      </div>
      <div>
        <div class="common-tab" >
          <el-input v-model="scheduleInfo.redTeam" style="width: 200px; border: 2px red solid;height: 40px;" />
        </div>
        <div class="common-tab" >
          <el-input v-model="scheduleInfo.redPlayer" style="width: 200px; border: 2px red solid;height: 40px;" />
        </div>
        <div class="common-tab">
          <div class="common-tab" style="border: 2px #548235 solid; width: 80px; border-radius: 5px;">
            <div class="tab-text">A --</div>
            <div class="tab-text">P --</div>
          </div>
          <div class="common-tab" style="border: 2px #548235 solid; width: 80px; border-radius: 5px;height: 52px;" >
            <div class="tab-text" style="color: #ffffff;background: green">--</div>
          </div>
        </div>
      </div>
    </div>
    <div class="edit-group-box" style="margin-bottom: 40px;" v-else-if="scheduleInfo.type === 2 && scheduleInfo.twoTime">
      <div>
        <div class="common-tab" >
          <el-input v-model="scheduleInfo.blueTeam" style="width: 200px; border: 2px #0070C0 solid;height: 40px;" />
        </div>
        <div class="common-tab" >
          <el-input v-model="scheduleInfo.bluePlayer" style="width: 200px; border: 2px #0070C0 solid;height: 40px;" />
        </div>
        <div class="common-tab" v-for="(item,index) in matchLogicScoreList" v-if="item.type == 1 || item.type == 3" :key="index">
          <div class="common-tab" v-if="item.type == 1" style="border: 2px #548235 solid; width: 80px; border-radius: 5px;">
            <div class="tab-text">A {{item.accuracyScore}}</div>
            <div class="tab-text">P {{item.expressivenessScore}}</div>
          </div>
          <div class="common-tab" v-if="item.type == 3" style="border: 2px #548235 solid; width: 80px; border-radius: 5px;">
            <div class="tab-text">A {{item.accuracyScore}}</div>
            <div class="tab-text">P {{item.expressivenessScore}}</div>
          </div>
          <div class="common-tab" @click="lockTwoTimeChanage1(item.type)" style="border: 2px #548235 solid; width: 80px; border-radius: 5px;height: 52px;" >
            <div v-if="scheduleInfo.lockTwoTime == item.type" class="common-tab" style="border: 2px #548235 solid; width: 80px; border-radius: 5px;height: 52px;" >
              <div class="tab-text" style="color: #ffffff;background: green">{{item.totalScore}}</div>
            </div>
            <div v-else class="tab-text">{{item.totalScore}}</div>
          </div>
        </div>
      </div>
      <div>
        <div class="common-tab" >
          <el-input v-model="scheduleInfo.redTeam" style="width: 200px; border: 2px #0070C0 solid;height: 40px;" />
        </div>
        <div class="common-tab" >
          <el-input v-model="scheduleInfo.redPlayer" style="width: 200px; border: 2px #0070C0 solid;height: 40px;" />
        </div>
        <div class="common-tab" v-for="(item,index) in matchLogicScoreList" v-if="item.type == 2 || item.type == 4" :key="index">
          <div class="common-tab" v-if="item.type == 2" style="border: 2px #548235 solid; width: 80px; border-radius: 5px;">
            <div class="tab-text">A {{item.accuracyScore}}</div>
            <div class="tab-text">P {{item.expressivenessScore}}</div>
          </div>
          <div class="common-tab" v-if="item.type == 4" style="border: 2px #548235 solid; width: 80px; border-radius: 5px;">
            <div class="tab-text">A {{item.accuracyScore}}</div>
            <div class="tab-text">P {{item.expressivenessScore}}</div>
          </div>
          <div class="common-tab" @click="lockTwoTimeChanage1(item.type)" style="border: 2px #548235 solid; width: 80px; border-radius: 5px;height: 52px;" >
            <div v-if="scheduleInfo.lockTwoTime == item.type" class="common-tab" style="border: 2px #548235 solid; width: 80px; border-radius: 5px;height: 52px;" >
              <div class="tab-text" style="color: #ffffff;background: green">{{item.totalScore}}</div>
            </div>
            <div v-else class="tab-text">{{item.totalScore}}</div>
          </div>
        </div>
      </div>
    </div>
    <div style="padding-top: 25px;width: 630px;" class="common-tab">
      <div style="padding-bottom: 10px;border-bottom: 1px #f5f2f0 solid">
        <div class="common-tab" style="width: 70px;">
          <div class="tab-text">#</div>
        </div>
        <div class="common-tab" style="width: 70px;display: none;">
          <div class="tab-text">id</div>
        </div>
        <div class="common-tab" style="width: 120px;">
          <div class="tab-text">名称</div>
        </div>
        <div class="common-tab" style="width: 200px;">
          <div class="tab-text">
            <div v-if="scheduleInfo.type == 1 || (scheduleInfo.type == 2 && scheduleInfo.twoTime)" style="width: 45px;background: #E8DDBC" class="tab-text" @click="nextScore">+0.1</div>
            <div style="padding: 0 5px 0 5px;">评分</div>
            <div v-if="scheduleInfo.type == 1 || (scheduleInfo.type == 2 && scheduleInfo.twoTime)" style="width: 45px;background: #B9CAA6" class="tab-text" @click="prevSocre">-0.1</div>
          </div>
        </div>
        <div class="common-tab" style="width: 150px;">
          <div class="tab-text">重新提交</div>
        </div>
      </div>
      <div style="padding: 10px 0 10px 0;border-bottom: 1px #f5f2f0 solid" v-for="(item,index) in matchScoreList" :key="item.refereeId">
        <div class="common-tab" style="width: 70px;">
          <div class="tab-text">{{index +1}}</div>
        </div>
        <div class="common-tab" style="width: 70px;display: none;">
          <div class="tab-text">{{item.refereeId}}</div>
        </div>
        <div class="common-tab" style="width: 120px;background: #45E18C;color: #ffffff;" v-if="item.isLogin == 1" >
          <div class="tab-text">
            <el-button type="primary" size="mini" @click="restLoginState(item.rId)">{{item.account}}</el-button>
          </div>
        </div>
        <div class="common-tab" style="width: 120px;background: #888080;color: #ffffff;" v-else>
          <div class="tab-text" >{{item.account}}</div>
        </div>
        <div class="common-tab" style="width: 200px;">
          <div class="tab-text">
            <div v-if="scheduleInfo.type == 1 || (scheduleInfo.type == 2 && scheduleInfo.twoTime)">
              <div class="common-tab">
                <el-input :value="item.accuracy" v-model="item.accuracy" style="width: 60px;border: 1px #f0f2f5 solid; height: 35px;"></el-input>
              </div>
              <div class="common-tab">
                <el-input :value="item.expressiveness" v-model="item.expressiveness"  style="width: 60px;border: 1px #f0f2f5 solid; height: 35px;"></el-input>
              </div>
              <div class="common-tab" style="width: 50px;border: 1px #f0f2f5 solid;">
                <el-button type="primary" plain @click="scoreBtn(index)">确定</el-button>
              </div>
            </div>
            <div v-if="scheduleInfo.type == 2 && !scheduleInfo.twoTime">
              <div class="common-tab"  style="background: #30BCA8;color: #ffffff;">
                <el-select v-model="item.winner" style="width:70px;">
                  <el-option :value="1" label='红' style="color: red;"></el-option>
                  <el-option :value="2" label='青' style="color: #1e6abc"></el-option>
                </el-select>
              </div>
              <div class="common-tab" style="width: 50px;border: 1px #f0f2f5 solid;">
                <el-button type="primary" plain @click="scoreBtn(index)">确定</el-button>
              </div>
            </div>
          </div>
        </div>
        <div class="common-tab" style="width: 150px;">
          <div class="tab-text" >
            <el-button  type="primary" @click="delectScoreBtn(index)">清除</el-button>
          </div>
        </div>
      </div>
      <div style="padding-top: 30px;">
        <el-button v-if="refreshThread" type="danger" @click="stopScoreBtn()">正刷新</el-button>
        <el-button v-if="!refreshThread" type="primary" @click="startScoreBtn()">开始刷新</el-button>
      </div>
      <div style="padding-top: 30px;">
        <div class="common-tab" style="padding-right: 10px">
          <el-button @click="scheduleStartBtn">开始</el-button>
        </div>
        <div class="common-tab" style="padding-right: 10px">
          <el-button @click="scheduleSuspendBtn">暂停</el-button>
        </div>
        <div class="common-tab" style="padding-right: 20px">
          <el-button @click="scheduleEndBtn">结束</el-button>
        </div>
        <div class="common-tab" style="padding-right: 20px">
          <el-button @click="logicScoreMe" :disabled="scheduleInfo.isLocked!=1">总分计算</el-button>
        </div>
        <div class="common-tab" style="padding-right: 20px" >
          <el-button @click="showLogicSocreMe" :disabled="scheduleInfo.isLocked!=1">总分公示</el-button>
        </div>
        <div class="common-tab" v-if="scheduleInfo.type == 1">
          <el-button @click="showRanking()" :disabled="scheduleInfo.isLocked!=1">排名公示</el-button>
        </div>
      </div>
    </div>
    <div class="common-tab" style="padding-top: 10px;">
      <div class="common-tab" style="border: 2px #548235 solid; width: 80px; border-radius: 5px;height: 50px;" >
        <div class="tab-text" v-if="scheduleInfo.type == 1 && !scheduleInfo.twoTime">A {{totlaLogicScoreData.A}}</div>
        <div class="tab-text" v-else-if="scheduleInfo.type == 1 && scheduleInfo.twoTime">A {{totlaLogicScoreData.T1}}</div>
        <div class="tab-text" v-else-if="scheduleInfo.type == 2 && !scheduleInfo.twoTime">青 {{totlaLogicScoreData.winner1}}</div>
        <div class="tab-text" v-else-if="scheduleInfo.type == 2 && scheduleInfo.twoTime">青 {{totlaLogicScoreData.T1}}</div>
      </div>
      <div class="common-tab" style="border: 2px #548235 solid; width: 80px; border-radius: 5px;height: 50px;">
        <div class="tab-text" v-if="scheduleInfo.type == 1 && !scheduleInfo.twoTime">P {{totlaLogicScoreData.P}}</div>
        <div class="tab-text" v-else-if="scheduleInfo.type == 1 && scheduleInfo.twoTime">P {{totlaLogicScoreData.T2}}</div>
        <div class="tab-text" v-else-if="scheduleInfo.type == 2 && !scheduleInfo.twoTime">红 {{totlaLogicScoreData.winner0}}</div>
        <div class="tab-text" v-else-if="scheduleInfo.type == 2 && scheduleInfo.twoTime">红 {{totlaLogicScoreData.T2}}</div>
      </div>
      <div :class="boxCheck==1 ? 'box-select' : ''" @click="boxSelect()" style="border: 2px #548235 solid; width: 163px; border-radius: 10px;height: 163px;margin-top: 10px;">
        <div class="tab-text" style="font-size: 40pt;color: #1e6abc" v-if="scheduleInfo.type == 1 && !scheduleInfo.twoTime">{{totlaLogicScoreData.T}}</div>
        <div class="tab-text" style="font-size: 40pt;color: #1e6abc" v-else-if="scheduleInfo.type == 1 && scheduleInfo.twoTime">{{totlaLogicScoreData.T3}}</div>
        <div class="tab-text" style="font-size: 40pt;" v-else-if="scheduleInfo.type == 2 && !scheduleInfo.twoTime">
          <div style="color: red" v-if="totlaLogicScoreData.winner0 > totlaLogicScoreData.winner1">红</div>
          <div style="color: #1e6abc" v-else-if="totlaLogicScoreData.winner0 < totlaLogicScoreData.winner1">青</div>
        </div>
        <div class="tab-text" style="font-size: 40pt;" v-else-if="scheduleInfo.type == 2 && scheduleInfo.twoTime">
          <div style="color: red;" v-if="totlaLogicScoreData.T1 > totlaLogicScoreData.T2">青</div>
          <div style="color: red" v-else-if="totlaLogicScoreData.T1 < totlaLogicScoreData.T2">红</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import { getScheduleInfo, getRefereeScoreList, showRanking, updateMatchSchedule, matchScheduleForCodeList, lockTwoTimeChange } from '@/api/matchSchedule'
  import { updateSocre, deleteById, next, prev, logicScore, getLogicScore, totlaLogicScore, showLogicSocre } from '@/api/matchScore'
  import { restSingleLoginState } from '@/api/referee'
  import { showMsg } from '@/utils'
  import { lock, unLocked } from '@/api/matchScheduleLocked'
  export default {
    props: {
      scheduleId: {
        type: Number,
        default: 0
      },
      matchId: {
        type: Number,
        default: 0
      },
      matchPlaceId: {
        type: Number,
        default: 0
      },
      scheduleList: {
        type: Array,
        default: []
      }
    },
    data() {
      return {
        scheduleInfo: {},
        matchScheduleForCodeList: null,
        scheduleNewId: null,
        matchScoreList: null,
        countdown: '',
        websocket: null,
        intervalFunc: null,
        matchLogicScoreList: null,
        boxCheck: 0,
        isRun: false,
        scoreListInter: null,
        refreshThread: true,
        totlaLogicScoreData: {
          A: 0,
          T: 0,
          P: 0,
          T1: 0,
          T2: 0,
          T3: 0
        }
      }
    },
    mounted() {
      if ('WebSocket' in window) {
        this.websocket = new WebSocket('ws://139.9.71.200/websocket/' + this.scheduleNewId + '/' + this.$store.state.user.matchAdminId + '/init/01:30')
        this.initWebSocket()
      } else {
        alert('当前浏览器 Not support websocket')
      }
    },
    beforeDestroy() {
      window.clearInterval(this.scoreListInter)
      window.clearInterval(this.scoreListInter)
    },
    created() {
      this.getScheduleInfoData()
      this.getMatchScheduleForCodeList()
    },
    methods: {
      initWebSocket() {
        this.websocket.onerror = this.setErrorMessage
        this.websocket.onopen = this.setOnopenMessage
        this.websocket.onmessage = this.setOnmessageMessage
        this.websocket.onclose = this.setOncloseMessage
        window.onbeforeunload = this.onbeforeunload
      },
      stopScoreBtn() {
        if (this.scoreListInter != null) {
          window.clearInterval(this.scoreListInter)
        }
        this.refreshThread = false
      },
      startScoreBtn() {
        this.getScheduleInfoData()
        this.refreshThread = true
      },
      boxSelect() {
        if (this.scheduleInfo.twoTime) {
          var obj = {
            matchScheduleId: this.scheduleId,
            status: 'twoTimefinalShow',
            sid: this.scheduleId,
            uid: this.$store.state.user.matchAdminId
          }
          if (this.boxCheck === 0) {
            this.boxCheck = 1
            obj.boxCheck = 1
          } else {
            this.boxCheck = 0
            obj.boxCheck = 0
          }
          this.websocket.send(JSON.stringify(obj))
        }
      },
      restLoginState(id) {
        restSingleLoginState(id).then(res => {
          if (res.data.code === 0) {
            showMsg(res.data.message, 1)
            this.getRefereeScoreList()
          } else {
            showMsg(res.data.message, 2)
          }
        })
      },
      setErrorMessage() {
        this.data = 'WebSocket连接发生错误' + '   状态码：' + this.websocket.readyState
      },
      setOnopenMessage() {
        this.data = 'WebSocket连接成功' + '   状态码：' + this.websocket.readyState
        window.setInterval(() => {
          var obj = {
            status: 'thread',
            sid: this.scheduleId,
            uid: this.$store.state.user.matchAdminId
          }
          this.websocket.send(JSON.stringify(obj))
        }, 3000)
      },
      setOncloseMessage() {
        this.data = 'WebSocket连接关闭' + '   状态码：' + this.websocket.readyState
      },
      onbeforeunload() {
        this.closeWebSocket()
      },
      closeWebSocket() {
        this.websocket.close()
      },
      scheduleStartBtn() {
        var obj = {
          status: 'start',
          sid: this.scheduleId,
          uid: this.$store.state.user.matchAdminId
        }
        this.websocket.send(JSON.stringify(obj))
      },
      scheduleSuspendBtn() {
        var obj = {
          status: 'suspend',
          sid: this.scheduleId,
          uid: this.$store.state.user.matchAdminId
        }
        this.websocket.send(JSON.stringify(obj))
      },
      scheduleEndBtn() {
        var obj = {
          status: 'stop',
          sid: this.scheduleId,
          uid: this.$store.state.user.matchAdminId
        }
        this.websocket.send(JSON.stringify(obj))
      },
      nextScore() {
        next({ matchScheduleId: this.scheduleInfo.id }).then(res => {
          if (res.data.code === 0) {
            showMsg(res.data.message, 1)
          } else {
            showMsg(res.data.message, 2)
          }
          this.getRefereeScoreList()
        })
      },
      prevSocre() {
        prev({ matchScheduleId: this.scheduleInfo.id }).then(res => {
          if (res.data.code === 0) {
            showMsg(res.data.message, 1)
          } else {
            showMsg(res.data.message, 2)
          }
          this.getRefereeScoreList()
        })
      },
      logicScoreMe() {
        var obj = {
          matchScheduleId: this.scheduleInfo.id,
          refereeType: this.scheduleInfo.refereeType,
          type: this.scheduleInfo.lockTwoTime
        }
        logicScore(obj).then(res => {
          if (res.data.code === 0) {
            showMsg(res.data.message, 1)
            this.getLogicScoreList()
            this.totlaLogicScoreMe()
          } else {
            showMsg(res.data.message, 2)
          }
        })
      },
      getLogicScoreList() {
        getLogicScore({ matchScheduleId: this.scheduleNewId, type: this.scheduleInfo.lockTwoTime }).then(res => {
          this.matchLogicScoreList = res.data.data
          var obj1 = {
            accuracyScore: '--',
            expressivenessScore: '--',
            totalScore: '--',
            winner: 1,
            type: 1
          }
          var obj2 = {
            accuracyScore: '--',
            expressivenessScore: '--',
            totalScore: '--',
            winner: 1,
            type: 2
          }
          var obj3 = {
            accuracyScore: '--',
            expressivenessScore: '--',
            totalScore: '--',
            winner: 1,
            type: 3
          }
          var obj4 = {
            accuracyScore: '--',
            expressivenessScore: '--',
            totalScore: '--',
            winner: 1,
            type: 4
          }
          if (!this.scheduleInfo.twoTime && this.scheduleInfo.type === 1) {
            if (this.matchLogicScoreList.length === 0) {
              this.matchLogicScoreList.push(obj1)
            }
          } else if (this.scheduleInfo.twoTime && this.scheduleInfo.type === 1) {
            if (this.matchLogicScoreList.length === 0) {
              this.matchLogicScoreList.push(obj1)
              this.matchLogicScoreList.push(obj2)
            } else if (this.matchLogicScoreList.length === 1) {
              var typeA = this.matchLogicScoreList[0].type
              if (typeA === 1) {
                this.matchLogicScoreList.push(obj2)
              } else if (typeA === 2) {
                this.matchLogicScoreList.splice(0, 0, obj1)
              }
            }
          } else if (this.scheduleInfo.twoTime && this.scheduleInfo.type === 2) {
            if (this.matchLogicScoreList.length === 0) {
              this.matchLogicScoreList.push(obj1)
              this.matchLogicScoreList.push(obj2)
              this.matchLogicScoreList.push(obj3)
              this.matchLogicScoreList.push(obj4)
            } else if (this.matchLogicScoreList.length === 1) {
              var type = this.matchLogicScoreList[0].type
              if (type === 1) {
                this.matchLogicScoreList.push(obj2)
                this.matchLogicScoreList.push(obj3)
                this.matchLogicScoreList.push(obj4)
              } else if (type === 2) {
                this.matchLogicScoreList.splice(0, 0, obj1)
                this.matchLogicScoreList.push(obj3)
                this.matchLogicScoreList.push(obj4)
              } else if (type === 3) {
                this.matchLogicScoreList.splice(0, 0, obj1)
                this.matchLogicScoreList.splice(1, 0, obj2)
                this.matchLogicScoreList.push(obj4)
              } else if (type === 4) {
                this.matchLogicScoreList.splice(0, 0, obj1)
                this.matchLogicScoreList.splice(1, 0, obj2)
                this.matchLogicScoreList.splice(2, 0, obj3)
              }
            } else if (this.matchLogicScoreList.length === 2) {
              var type11 = this.matchLogicScoreList[0].type
              var type22 = this.matchLogicScoreList[1].type
              if (type11 === 1 && type22 === 2) {
                this.matchLogicScoreList.splice(2, 0, obj3)
                this.matchLogicScoreList.splice(3, 0, obj4)
              } else if (type11 === 1 && type22 === 3) {
                this.matchLogicScoreList.splice(1, 0, obj2)
                this.matchLogicScoreList.splice(3, 0, obj4)
              } else if (type11 === 1 && type22 === 4) {
                this.matchLogicScoreList.splice(1, 0, obj2)
                this.matchLogicScoreList.splice(2, 0, obj3)
              } else if (type11 === 2 && type22 === 3) {
                this.matchLogicScoreList.splice(0, 0, obj1)
                this.matchLogicScoreList.push(obj4)
              } else if (type11 === 2 && type22 === 4) {
                this.matchLogicScoreList.splice(0, 0, obj1)
                this.matchLogicScoreList.splice(2, 0, obj3)
              } else if (type11 === 3 && type22 === 4) {
                this.matchLogicScoreList.splice(0, 0, obj1)
                this.matchLogicScoreList.splice(1, 0, obj2)
              }
            } else if (this.matchLogicScoreList.length === 3) {
              var type1 = this.matchLogicScoreList[0].type
              var type2 = this.matchLogicScoreList[1].type
              var type3 = this.matchLogicScoreList[2].type
              if (type1 === 1 && type2 === 2 && type3 === 3) {
                this.matchLogicScoreList.push(obj4)
              } else if (type1 === 1 && type2 === 2 && type3 === 4) {
                this.matchLogicScoreList.splice(2, 0, obj3)
              } else if (type1 === 2 && type2 === 3 && type3 === 4) {
                this.matchLogicScoreList.splice(0, 0, obj1)
              }
            }
          }
        })
      },
      totlaLogicScoreMe() {
        var obj = {
          matchScheduleId: this.scheduleNewId,
          scheduleType: this.scheduleInfo.type,
          scoreType: this.scheduleInfo.lockTwoTime
        }
        totlaLogicScore(obj).then(res => {
          this.totlaLogicScoreData = res.data.data
        })
      },
      showLogicSocreMe() {
        showLogicSocre({ matchScheduleId: this.scheduleNewId, type: this.scheduleInfo.lockTwoTime }).then(res => {
          if (res.data.code === 0) {
            showMsg(res.data.message, 1)
          } else {
            showMsg(res.data.message, 2)
          }
          var obj = {
            status: 'publish',
            sid: this.scheduleId,
            uid: this.$store.state.user.matchAdminId
          }
          this.websocket.send(JSON.stringify(obj))
        })
      },
      getMatchScheduleForCodeList() {
        const params = { matchId: this.matchId, matchPlaceId: this.matchPlaceId }
        // params.matchId=this.matchId;
        // params.matchPlaceId=this.matchPlaceId;

        matchScheduleForCodeList(params).then(res => {
          this.matchScheduleForCodeList = res.data.data
        })
      },
      showRanking() {
        showRanking({ matchScheduleId: this.scheduleInfo.id }).then(res => {
          if (res.data.code === 0) {
            showMsg(res.data.message, 1)
            var obj = {
              status: 'orderIndexPublish',
              sid: this.scheduleId,
              uid: this.$store.state.user.matchAdminId
            }
            this.websocket.send(JSON.stringify(obj))
          } else {
            showMsg(res.data.message, 2)
          }
        })
      },
      getScheduleInfoData() {
        if (this.scoreListInter != null) {
          window.clearInterval(this.scoreListInter)
        }
        this.scheduleNewId = this.scheduleId
        getScheduleInfo({ matchScheduleId: this.scheduleId, type: 1 }).then(res => {
          this.scheduleInfo = res.data.data
          this.getLogicScoreList()
          this.totlaLogicScoreMe()
          this.getRefereeScoreList()
          this.scoreListInter = window.setInterval(() => {
            this.getRefereeScoreList()
          }, 5000)
        })
      },
      getScheduleInfoNewData() {
        getScheduleInfo({ matchScheduleId: this.scheduleNewId }).then(res => {
          this.scheduleInfo = res.data.data
          this.getLogicScoreList()
          this.totlaLogicScoreMe()
          this.getRefereeScoreList()
        })
      },
      jumpToSchedule(matchId, matchScheduleId) {
        var obj = {
          matchId: matchId,
          matchAdminId: this.$store.state.user.matchAdminId,
          matchScheduleId: matchScheduleId
        }
        lock(obj).then(res => {
          if (res.data.code === 0) {
            showMsg(res.data.message, 1)
            var obj = {
              status: 'switchSchedule',
              sid: matchScheduleId,
              uid: this.$store.state.user.matchAdminId
            }
            this.websocket.send(JSON.stringify(obj))
          } else {
            showMsg(res.data.message, 2)
          }
          this.getScheduleInfoNewData()
        })
      },
      unjumpToSchedule(lockId) {
        var obj = []
        obj.push(lockId)
        unLocked(obj).then(res => {
          if (res.data.code === 0) {
            showMsg(res.data.message, 1)
          } else {
            showMsg(res.data.message, 2)
          }
          this.getScheduleInfoNewData()
        })
      },
      getRefereeScoreList() {
        var obj = {
          matchScheduleId: this.scheduleNewId,
          matchId: this.scheduleInfo.matchId,
          matchAdminId: this.$store.state.user.matchAdminId,
          scoreType: this.scheduleInfo.lockTwoTime
        }
        getRefereeScoreList(obj).then(res => {
          this.matchScoreList = res.data.data
        })
      },
      scoreBtn(index) {
        var obj = this.matchScoreList[index]
        obj.scoreType = this.scheduleInfo.lockTwoTime
        updateSocre(obj).then(res => {
          if (res.data.code === 0) {
            showMsg(res.data.message, 1)
            this.getRefereeScoreList()
          } else {
            showMsg(res.data.message, 2)
          }
        })
      },
      delectScoreBtn(index) {
        var obj = {
          id: this.matchScoreList[index].id
        }
        deleteById(obj).then(res => {
          if (res.data.code === 0) {
            showMsg(res.data.message, 1)
            this.getRefereeScoreList()
          } else {
            showMsg(res.data.message, 2)
          }
        })
      },
      topSchedule() {
        var CodeList = this.matchScheduleForCodeList
        for (var i = 0; i < CodeList.length; i++) {
          var sId = CodeList[i].id
          if (this.scheduleNewId === sId & i < CodeList.length) {
            this.scheduleNewId = CodeList[i + 1].id
            this.getScheduleInfoNewData()
            return
          }
        }
      },
      buttomSchedule() {
        var CodeList = this.matchScheduleForCodeList
        for (var i = 0; i < CodeList.length; i++) {
          var sId = CodeList[i].id
          if (this.scheduleNewId === sId & i > 0) {
            this.scheduleNewId = CodeList[i - 1].id
            this.getScheduleInfoNewData()
            return
          }
        }
      },
      matchScheduleChange() {
        var obj = {
          matchStatus1: this.scheduleInfo.matchStatus1,
          matchStatus2: this.scheduleInfo.matchStatus2,
          id: this.scheduleInfo.id,
          blueTeam: this.scheduleInfo.blueTeam,
          bluePlayer: this.scheduleInfo.bluePlayer,
          redTeam: this.scheduleInfo.redTeam,
          redPlayer: this.scheduleInfo.redPlayer
        }
        updateMatchSchedule(obj).then(res => {
          if (res.data.code === 0) {
            showMsg(res.data.message, 1)
            var obj = {
              status: 'updateInfo',
              sid: this.scheduleId,
              uid: this.$store.state.user.matchAdminId
            }
            this.websocket.send(JSON.stringify(obj))
          } else {
            showMsg(res.data.message, 2)
          }
        })
      },
      lockTwoTimeChanage1(type) {
        if (this.$store.state.user.matchAdminId !== 8888) {
          this.scheduleInfo.lockTwoTime = type
          var obj = {
            lockTwoTime: type,
            matchScheduleId: this.scheduleNewId
          }
          // 处理 02 ->解锁->换03->锁定->点分数  不切换到原id，使用新的替换
          this.$emit('update:scheduleId', this.scheduleNewId)
          lockTwoTimeChange(obj).then(res => {
            if (res.data.code === 0) {
              showMsg(res.data.message, 1)
              this.getScheduleInfoData()
            } else {
              showMsg(res.data.message, 2)
            }
          })
        }
      }
    }
  }
</script>

<style scoped>
  .edit-top{
    height: 100px;
    width: 100%;
  }
  .no-btn{
    background: #DBDB0F;
    line-height: 60px;
    width: 120px;
    border-radius: 10px;
  }
  .group-vs-text{
    background: #A4B0BF;
    height: 40px;
    margin-left: 20px;
  }
  .tab-text{
    height: 100%;
    display: -webkit-box;             /*flex弹性布局*/
    -webkit-box-align: center;
    -webkit-box-pack: center;
    font-size: 12pt;
  }
  .edit-lock-btn{
    background: #5D8532;
    line-height: 22px;
    width: 100%;
    margin-top: 5px;
    color: #ffffff;
  }
  .edit-group-box{
    height: 50px;
  }
  .box-select{
    background: green;
  }
</style>
